<template>
    <div class="box">
        <h2>Son2 子组件</h2>
        从vuex中获取的值:<label>{{ count }}</label>
        <br />
        <button @click="handleSub(1)">值 - 1</button>
        <button @click="handleSub(5)">值 - 5</button>
        <button @click="handleSub(10)">值 - 10</button>
        <button @click="handleSubWithParam(15)">值 - 15</button>
        <button @click="handleSubWithParam(20)">值 - 20</button>
        <button @click="changeTitle">改标题</button>
        <button @click="changeCountAsync(888)">改数据为888</button>
        <hr>
        <div>mapGetters {{ filterList }}</div>
    </div>
</template>

<script>
import { mapState, mapMutations, mapActions, mapGetters } from 'vuex'

export default {
  name: 'Son2Com',
  computed: {
    // mapState 和 mapGetters 都是映射属性
    ...mapState(['count']),
    ...mapGetters(['filterList'])
  },
  methods: {
    handleSub (n) {
      this.$store.commit('handleSubWithParam', n)
    },
    // mapMutations 和 mapActions 都是映射方法
    ...mapMutations(['handleSubWithParam', 'changeTitle']),
    ...mapActions(['changeCountAsync'])
  }
}
</script>

<style lang="css" scoped>
.box {
    border: 3px solid #ccc;
    width: 400px;
    padding: 10px;
    margin: 20px;
}

h2 {
    margin-top: 10px;
}
</style>
